1How to Send Customized E-Mail 2 3So you wish to send out customized e-mail to many people? Please reconsider 4doing that, if it is unwanted spam. Still want to do it? Here's one way of 5doing it: 6 7Save your message text in a file named "TemplateLetter.txt". It should look 8something like this (I didn't word wrap the paragraphs, leaving each as one 9long line, because the length would change depending on the inserted text 10length): 11 12Hi there NAME, how are you today? 13 14I'm sending this message to EMAIL to inform you about a good deal for your company, COMPANY. 15 16Hope you like it. 17 18- Alex 19 20 21Then save this following text as a script file, call it "MailToTemplate": 22 23#!/bin/sh 24 25# Make a mail merge letter by combining data from a given people file and a 26# template letter text file. 27# $Revision: 1.2 $ 28# Some code from Scot Hacker's PeoplePorter http://www.bebits.com/app/1747 29 30PeopleFile=$1 31echo "Mail merging using people file: $PeopleFile" 32 33Name=$(catattr META:name "$PeopleFile" | sed s/\ \:\ /%/g | cut -f3 -d\%) 34EMail=$(catattr META:email "$PeopleFile" | sed s/\ \:\ /%/g | cut -f3 -d\%) 35Company=$(catattr META:company "$PeopleFile" | sed s/\ \:\ /%/g | cut -f3 -d\%) 36 37sed "s/NAME/$Name/g" <TemplateLetter.txt >/tmp/stage1 38sed "s/EMAIL/$EMail/g" </tmp/stage1 >/tmp/stage2 39sed "s/COMPANY/$Company/g" </tmp/stage2 >/tmp/stage3 40mail -v -s "Test Message to $Name" "$EMail" </tmp/stage3 41 42 43After you have saved it, make it executable with the "chmod a+x MailToTemplate" 44command. Then run it with a people file as an argument: 45 46Fri Jun 13 12:13:11 67 /Programming/bemaildaemon/documentation/Mass Mailing>MailToTemplate /boot/home/people/Test\ Person 47Mail merging using people file: /boot/home/people/Test Person 48EOT 49sent successfully! 50 51 52And the result will be an e-mail like this: 53 54Subject: Test Message to Mr. Test A. Person 55To: test@be.com 56Date: Fri, 13 Jun 2003 12:13:29 -0400 EDT 57Mime-Version: 1.0 58Content-Type: text/plain; charset="iso-8859-1" 59Content-Transfer-Encoding: quoted-printable 60 61Hi there Mr. Test A. Person, how are you today=3F 62 63I'm sending this message to test@be.com to inform you about a good deal for your company, Masters of Scripting, Inc.. 64 65Hope you like it. 66 67- Alex 68 69 70If you want to use the BeOS attribute indices system to select people, you can 71run the results of a query though the mail customizing script like this example 72(watch out - very long line) which sends the e-mail to all people (presumably 73the people files are on the /boot disk volume, which is why the -v is needed) 74with "test" in their groups listing: 75 76Fri Jun 13 12:24:14 78 /Programming/bemaildaemon/documentation/Mass Mailing>query -v /boot META:group=*test* | sed "s/^/MailToTemplate /g" >/tmp/BatchMailCommands ; source /tmp/BatchMailCommands 77Mail merging using people file: /boot/home/people/Test Person 78EOT 79sent successfully! 80Mail merging using people file: /boot/home/people/Another Test 81EOT 82sent successfully! 83 84 85Just so you know how it works, here is the batch commands file which was 86automatically generated and used in the previous step: 87 88Fri Jun 13 12:24:20 79 /Programming/bemaildaemon/documentation/Mass Mailing>cat /tmp/BatchMailCommands 89MailToTemplate /boot/home/people/Test\ Person 90MailToTemplate /boot/home/people/Another\ Test 91 92 93Finally, if you want to do fancier messages, like HTML mixed ones, you have to 94also specify the headers. Since the usual "mail" program doesn't let you do 95that, you have to prepare the entire message and use the attribute system to 96tag it for mailing. Look at an existing message in your out box to see the 97attributes needed. 98 99Prepare the message elsewhere (use some other e-mail package which lets you 100insert HTML and pictures) then mail it to yourself, open the resulting file in 101BeIDE (it takes care of the CRLF end of line conversion problems automatically, 102you want this template file to have CRLF line ends, the earlier example doesn't 103use them) and edit it to make it into a new message like this one: 104 105 106To: "NAME" <EMAIL> 107From: "Imaginary Test Account" <test@be.com> 108Subject: Hi there NAME 109Mime-Version: 1.0 110Content-Type: multipart/related; 111 type="multipart/alternative"; 112 boundary="----=_NextPart_000_0009_01C331AA.016FA080" 113 114This is a multi-part message in MIME format. 115 116------=_NextPart_000_0009_01C331AA.016FA080 117Content-Type: multipart/alternative; 118 boundary="----=_NextPart_001_000A_01C331AA.016FA080" 119 120 121------=_NextPart_001_000A_01C331AA.016FA080 122Content-Type: text/plain; 123 charset="iso-8859-1" 124Content-Transfer-Encoding: quoted-printable 125 126Hi NAME, this is a reminder that you shouldn't annoy people with [No Spam Icon] spam! 127 128-------------------------------------------------------------------------------- 129 130Fine print: Even if it is customised and otherwise pretty. 131------=_NextPart_001_000A_01C331AA.016FA080 132Content-Type: text/html; 133 charset="iso-8859-1" 134Content-Transfer-Encoding: quoted-printable 135 136<HTML><HEAD><TITLE>This is your Spam!</TITLE></HEAD> 137<BODY BGCOLOR=3DWHITE> 138<P>Hi NAME, this is a <STRONG>reminder</STRONG> that <FONT COLOR=3DBLUE SIZE=3D5>you</FONT> 139<STRONG>shouldn't</STRONG> annoy <FONT COLOR=3DRED>people</FONT> with 140<IMG alt=3D"[No Spam Icon]" WIDTH=3D32 HEIGHT=3D32 141SRC=3D"cid:000801c331cb$88136380$42ae10ac@be.com" 142BORDER=3D0> spam! 143<HR> 144<P><FONT size=3D1>Fine print: Even if it is customised and otherwise 145pretty.</FONT> 146</BODY></HTML> 147 148------=_NextPart_001_000A_01C331AA.016FA080-- 149 150------=_NextPart_000_0009_01C331AA.016FA080 151Content-Type: image/png; 152 name="NoSpamIcon.png" 153Content-Transfer-Encoding: base64 154Content-ID: <000801c331cb$88136380$42ae10ac@be.com> 155 156iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABTElEQVR42r2XDQ6DMAhGuVPvtHP0 157GN5ph2KpqY5QoF/xx4Rs2UzfAysKMXAQUSqgtREwJwMRoQhuLVon4YksCVAAnh2eiCdBMzgKRkQs 158CZrBrxwEVILehFsS9BbcuxyDwGPwvi8GgTuzj+BaQPQJ/J6ddUcLrjtjvSpwLrZ9mL/bHmHm7bwe 159pPbCIGDepzqLDm1RgswlmEv5f4oqhAIW8IyefQjv553VavAeoYALFiUP4fJ8HYiABhfx2/F9mrkU 160VnC5D3wBla1cFMo8KP9yBaDdLs4pcgMem2+pAn2xomQ8eAGvu9UL4AqEZQ+gGqw74v6f2aOR3Q5A 161rb4yNKJIAG4yQbbLArzQ21ffgk2OZ8Y3vyO4j2PP7km4KeBJPAk334prYrjIwt25oCanHPkUTb2W 162zyQYmQcXpyPKTDmZGTE1nGqR+uZweseojhw/XAq+WQDwT5wAAAAASUVORK5CYII= 163 164------=_NextPart_000_0009_01C331AA.016FA080-- 165 166 167Then in the mailing script, rather than calling "mail" to do the job, you have 168to add attributes to the final file. Some you can clone from another outgoing 169mail (like the chain), others you need to set to specify the recipient. Here's 170the current full set: 171 172 Type Size Name 173---------- --------- ------------------------------- 174 MIME str 13 BEOS:TYPE 175 Text 46 MAIL:recipients 176 Text 43 MAIL:to 177 Text 1 MAIL:cc 178 Text 42 MAIL:subject 179 Text 1 MAIL:reply 180 Text 46 MAIL:from 181 Text 4 MAIL:mime 182 Text 18 MAIL:account 1830x54494d45 4 MAIL:when 184 Int-32 4 MAIL:flags 185 Int-32 4 MAIL:chain 186 Text 5 MAIL:status 187 188You need at the minimum: 189BEOS:TYPE set to: text/x-email 190MAIL:recipients lists the address you are sending to, for example: <test@be.com> 191MAIL:from lists your return address: "Imaginary Test Account" <test@be.com> 192MAIL:chain set to your outgoing mail chain number, happens to be 1 here. 193MAIL:flags set to 5. 194 195The commands to do that look like: 196addattr -t string BEOS:TYPE text/x-email /tmp/stage3 197addattr -t string MAIL:recipients "<$EMail>" /tmp/stage3 198addattr -t string MAIL:from "\"Imaginary Test Account\" <test@be.com>" /tmp/stage3 199addattr -t int MAIL:chain 1 /tmp/stage3 200addattr -t int MAIL:flags 5 /tmp/stage3 201 202Then move the message to the /boot/home/mail/out folder, using a unique name, 203since there has to be one file for each person. A suitable command might be: 204mv /tmp/stage3 "/boot/home/mail/out/MessageTo$EMail" 205 206Finally, tell the daemon to check for mail. Right click on the mailbox icon in 207the deskbar and pick "check for mail". It will then send all the pending mail. 208